package com.leiduoduo.oms.service;

import com.leiduoduo.oms.dao.DinnerDao;
import com.leiduoduo.oms.pojo.Dinner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class DinnerServiceImpl implements DinnerService {
    @Autowired
    DinnerDao dinnerDao;

    @Override
    public boolean addDinner(Dinner dinner) {
        dinner.setCreated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dinnerDao.addDinner(dinner);
    }

    @Override
    public boolean delDinner(Dinner dinner) {
        dinner.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dinnerDao.delDinner(dinner);
    }

    @Override
    public boolean upDinner(Dinner dinner) {
        dinner.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return dinnerDao.upDinner(dinner);
    }

    @Override
    public Dinner getDinnerByCode(String code) {
        return dinnerDao.getDinnerByCode(code);
    }

    @Override
    public List<Dinner> getDinnerList() {
        return dinnerDao.getDinnerList();
    }
}
